package com.neusoft.bizcore.activiti.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.validator.constraints.Length;

import com.neusoft.bizcore.activiti.enums.FormType;
import com.neusoft.bizcore.web.jpa.model.AbstractModel;
import com.neusoft.bizcore.web.jpa.model.Comment;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@Table(name = "wf_process_form")
@org.hibernate.annotations.Table(appliesTo = "wf_process_form", comment = "流程表单表")
public class ProcessForm extends AbstractModel {

    private static final long serialVersionUID = 1L;

    @NotBlank(message = "表单名不能为空")
    @Length(max = 255, message = "表单名不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '表单名称'")
    private String name;

    @NotBlank(message = "编码不能为空")
    @Length(max = 255, message = "编码不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '编码'")
    private String code;

    @NotBlank(message = "工单类型不能为空")
    @Length(max = 255, message = "工单类型不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '工单类型'")
    private String workType;

    /** 表单类型 */
    @Enumerated(EnumType.STRING)
    @NotNull(message = "表单类型不能为空")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) COMMENT '表单类型'")
    private FormType type = FormType.other;

    /** 关联字段详细 */
    @OneToMany(mappedBy = "form", cascade = {CascadeType.ALL }, fetch = FetchType.EAGER)
    @LazyCollection(LazyCollectionOption.FALSE)
    List<ProcessFormItem> items = new ArrayList<>();

    /** 关联类型 */
    @ManyToMany
    @LazyCollection(LazyCollectionOption.FALSE)
    List<Process> process = new ArrayList<>();

}
